<%@page contentType="text/html; charset=UTF-8" import="hotel.entity.*,java.util.*" pageEncoding="UTF-8"%>
<%@include file="../link.html"%>
<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function() {
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});

});
	
function editUser(){
	var index=$('#btn-submit').attr('class').indexOf("disabled");
	var form = new FormData(document.getElementById("userForm"));
	if(index==-1){//disabled的下标为-1说明确定按钮可用
		$.ajax({
	        type:"post",
	        url:"editUser",
	        data: form,
	        processData: false,  
	        contentType: false,
	        success: function(data){
	        	layer.msg('修改成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭 
				});  
	        }
	    });
	}
	return false;
}
</script>

<div style="padding-top:25px;">
	<form id="userForm" method="post" action="editUser" class="form-horizontal" 
	data-toggle="validator" role="form" enctype="multipart/form-data">
	
		<input type="hidden" name="userid" value="${user.userid}">
		<input type="hidden" name="registeredTime" value="${user.registeredTime}">
		<input type="hidden" name="image" value="${user.image}">
		
		<div class="form-group">
			<label  class="col-sm-4 control-label">登录账号<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="account" name="account" value="${user.account}" class="form-control" readonly>
			</div>
		</div>

		<div class="form-group">
			<label  class="col-sm-4 control-label">密码<span style="color:red;">*</span></label>
			<div class="col-sm-5">
			<input id="password" type="password" name="password" 
			value="${user.password}" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">重复密码</label>
			<div class="col-sm-5">
				<input id="passwordRepeat" type="password" class="form-control">
			</div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">姓名<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="name" name="name" value="${user.name}" class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">性别</label>
			<div class="col-sm-1">
				<input type="radio" name="gender" class="iradio_minimal" 
				<%if(((User)request.getAttribute("user")).getGender().equals("男")) out.print("checked");%>
				value="男"> 男
			</div>
			<div class="col-sm-1">
				<input type="radio" name="gender" class="iradio_minimal" 
				<%if(((User)request.getAttribute("user")).getGender().equals("女")) out.print("checked");%>
				value="女"> 女
			</div>
		</div>
		<div class="form-group">
			<label  class="col-sm-4 control-label">手机号码<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<input id="telephone" name="telephone" value="${user.telephone}" 
				class="form-control" required>
			</div>
			<div class="help-block with-errors"></div>
		</div>
		<div class="form-group">
			<label class="col-sm-4 control-label">用户角色<span style="color:red;">*</span></label>
			<div class="col-sm-5">
				<select id="select" name="role.roleid" class="form-control">
				<%
				List<Role> list=(List<Role>)request.getAttribute("roleList");
				if(list!=null&&list.size()>0)
				for(Role r:list){
					out.print("<option value='"+r.getRoleid()+"'>"+r.getRoleName()+"</option>");
				}
				%>
				</select>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">用户头像</label>
			<div class="col-sm-5">
				<input type="file" name="user_image">
			</div>
		</div>

		<div class="box-footer"></div>

		<div class="form-group">
			<label class="col-sm-4 control-label"></label>
			<div class="col-sm-5">
				<div class="pull-right">
					<button id="btn-submit" type="submit" class="btn btn-primary" onClick="return editUser()">
						<i class="fa fa-floppy-o "></i> 确定
					</button>
					<button id="btn-close" class="btn btn-close btn-primary" type="button">
						<i class="fa fa-remove"></i> 关闭
					</button>
				</div>
			</div>
		</div>
	</form>
</div>